from app.models.ServicesScopes import ServicesScopes
from schemas.services_scopes import Create, Update


class ScopesServices:
    @staticmethod
    def bulk_create(lists: list, services_id: int):
        print(lists)
        new_list = []
        for i, item in enumerate(lists, start=1):
            new_item = item.dict()
            new_item['sid'] = services_id
            new_list.append(new_item)
        data = ServicesScopes.bulk_create(new_list)
        return data

    @staticmethod
    def get_all(sid: int, current, size):
        data = ServicesScopes.where('sid', '=', sid).paginate(current, size)
        return data

    @staticmethod
    def get_one(Id: int):
        data = ServicesScopes.find(Id)
        return data

    @staticmethod
    def update(form: Update, category_id: str):
        data = ServicesScopes.find(category_id)
        data.update(form.model_dump())
        return data

    @staticmethod
    def delete(Id):
        data = ServicesScopes.find(Id)
        data.delete()
        return data
